/*
 * Copyright 2012 Benoît Combe <benoit.combe@gmail.com>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package fr.ipst.spot.entites;

import fr.ipst.spot.entites.utils.RoleOrganisme;
import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Benoît Combe <benoit.combe@gmail.com>
 */
@Entity
@Table(name = "Organisme", catalog = "SPOT", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Organisme.findAll", query = "SELECT o FROM Organisme o"),
    @NamedQuery(name = "Organisme.findByIdOrganisme", query = "SELECT o FROM Organisme o WHERE o.idOrganisme = :idOrganisme"),
    @NamedQuery(name = "Organisme.findByNom", query = "SELECT o FROM Organisme o WHERE o.nom = :nom"),
    @NamedQuery(name = "Organisme.findByAdresse", query = "SELECT o FROM Organisme o WHERE o.adresse = :adresse"),
    @NamedQuery(name = "Organisme.findByCodePostal", query = "SELECT o FROM Organisme o WHERE o.codePostal = :codePostal"),
    @NamedQuery(name = "Organisme.findByVille", query = "SELECT o FROM Organisme o WHERE o.ville = :ville"),
    @NamedQuery(name = "Organisme.findByRole", query = "SELECT o FROM Organisme o WHERE o.role = :role")})
public class Organisme extends AbstractSpotEntite implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idOrganisme", nullable = false)
    private Integer idOrganisme;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "nom", nullable = false, length = 255)
    private String nom;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "adresse", nullable = false, length = 255)
    private String adresse;
    @Basic(optional = false)
    @NotNull
    @Column(name = "codePostal", nullable = false)
    private int codePostal;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 255)
    @Column(name = "ville", nullable = false, length = 255)
    private String ville;
    @Basic(optional = false)
    @NotNull
    @Column(name = "role", nullable = false)
    @Enumerated(EnumType.ORDINAL)
    private RoleOrganisme role;
    @OneToMany(mappedBy = "organisme", fetch = FetchType.LAZY)
    private List<AgentExterieur> agentExterieurList;

    /**
     *
     */
    public Organisme() {
    }

    /**
     *
     * @param idOrganisme
     */
    public Organisme(Integer idOrganisme) {
        this.idOrganisme = idOrganisme;
    }

    /**
     *
     * @param idOrganisme
     * @param nom
     * @param adresse
     * @param codePostal
     * @param ville
     * @param role
     */
    public Organisme(Integer idOrganisme, String nom, String adresse, int codePostal, String ville, RoleOrganisme role) {
        this.idOrganisme = idOrganisme;
        this.nom = nom;
        this.adresse = adresse;
        this.codePostal = codePostal;
        this.ville = ville;
        this.role = role;
    }

    /**
     *
     * @return
     */
    public Integer getIdOrganisme() {
        return idOrganisme;
    }

    /**
     *
     * @param idOrganisme
     */
    public void setIdOrganisme(Integer idOrganisme) {
        this.idOrganisme = idOrganisme;
    }

    /**
     *
     * @return
     */
    public String getNom() {
        return nom;
    }

    /**
     *
     * @param nom
     */
    public void setNom(String nom) {
        this.nom = nom;
    }

    /**
     *
     * @return
     */
    public String getAdresse() {
        return adresse;
    }

    /**
     *
     * @param adresse
     */
    public void setAdresse(String adresse) {
        this.adresse = adresse;
    }

    /**
     *
     * @return
     */
    public int getCodePostal() {
        return codePostal;
    }

    /**
     *
     * @param codePostal
     */
    public void setCodePostal(int codePostal) {
        this.codePostal = codePostal;
    }

    /**
     *
     * @return
     */
    public String getVille() {
        return ville;
    }

    /**
     *
     * @param ville
     */
    public void setVille(String ville) {
        this.ville = ville;
    }

    /**
     *
     * @return
     */
    public RoleOrganisme getRole() {
        return role;
    }

    /**
     *
     * @param role
     */
    public void setRole(RoleOrganisme role) {
        this.role = role;
    }

    /**
     *
     * @return
     */
    @XmlTransient
    public List<AgentExterieur> getAgentExterieurList() {
        return agentExterieurList;
    }

    /**
     *
     * @param agentExterieurList
     */
    public void setAgentExterieurList(List<AgentExterieur> agentExterieurList) {
        this.agentExterieurList = agentExterieurList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idOrganisme != null ? idOrganisme.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Organisme)) {
            return false;
        }
        Organisme other = (Organisme) object;
        if ((this.idOrganisme == null && other.idOrganisme != null) || (this.idOrganisme != null && !this.idOrganisme.equals(other.idOrganisme))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "fr.ipst.spot.entites.Organisme[ idOrganisme=" + idOrganisme + " ]";
    }

    /**
     *
     * @return
     */
    @Override
    public Integer getId() {
        return this.idOrganisme;
    }
}
